{
Traviesadora beta 0.2.0.13.33 (30.11.2008)
LastMod: 12.12.2008 by Prof1983

Copyright 2008, travieorama@googlemail.com

This file is part of the taviesadora project

taviesadora is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

taviesadora is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
}
unit popup;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, Sockets, StdCtrls,ChatDistributer;

type
  TPopUpAction=(paNone,paMovie,paPresence);

type
  Tfrm_popup = class(TForm)
    Timer1: TTimer;
    Panel1: TPanel;
    Label1: TLabel;
    Button2: TButton;
    Button1: TButton;
    tmrclose: TTimer;
    Image1: TImage;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Timer1Timer(Sender: TObject);
    procedure FormClick(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Panel1Click(Sender: TObject);
    procedure Label1Click(Sender: TObject);
    procedure tmrcloseTimer(Sender: TObject);
  private
    ExtraString: string;
    jid: string;
    nick: string;
    chatdistri: TChatDistri;
    Action: TPopUpAction;
  public
    constructor Init(PopUpAction: TPopUpAction; ExtraStr, jid, Nick: string; ChatDistri: TChatDistri);
  end;

var
  frm_popup: Tfrm_popup;

implementation

uses
  Jabber, TraviesadoraCore;

{$R *.dfm}

constructor Tfrm_popup.Init(PopUpAction: TPopUpAction; ExtraStr, jid, Nick: string; ChatDistri: TChatDistri);
var
  showName: string;
begin
  Show();

  self.jid := jid;
  self.chatdistri := ChatDistri;
  self.nick := nick;
  if nick <> '' then
    showName := nick
  else
    showName := jid;
  Action:=PopUpAction;
  ExtraString := ExtraStr;
  SetForegroundWindow(Application.MainForm.Handle);
  Width := 150;
  height := 150;
  left := Screen.Width-width;
  top := Screen.Height;
  case Action of
    paMovie:
      begin
        Label1.Caption := 'Wanna watch a movie con '+showName+'?';
      end;
    paPresence:
      begin
        Label1.Caption := jid+' is Online';
        height := 100;
        Button1.Visible := false;
        Button2.Visible := false;
        tmrclose.Enabled := true;
      end;
  else
    begin
      Label1.Caption := '';
      Button1.Visible := false;
      Button2.Visible := false;
    end;
  end;
  timer1.Tag := 20;
  timer1.Enabled := True;
end;

procedure Tfrm_popup.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := cafree;
end;

procedure Tfrm_popup.tmrcloseTimer(Sender: TObject);
begin
  timer1.Tag := -20;
  timer1.Enabled := True;
end;

procedure Tfrm_popup.Timer1Timer(Sender: TObject);
begin
  top := top-timer1.Tag;
  if (timer1.Tag > 0) then
  begin
    if top < Screen.Height-height then
    begin
      timer1.Enabled := False;
    end;
  end
  else
  begin
    if (top > Screen.Height) then
    begin
      timer1.Enabled := False;
      Close;
    end;
  end;
end;

procedure Tfrm_popup.FormClick(Sender: TObject);
begin
  Close;
end;

procedure Tfrm_popup.Button2Click(Sender: TObject);
begin
  Close;
end;

procedure Tfrm_popup.Button1Click(Sender: TObject);
begin
  if (Action = paMovie) then
    ChatDistri.MovieAccepted(nil);
  Close;
end;

procedure Tfrm_popup.Panel1Click(Sender: TObject);
begin
  Close;
end;

procedure Tfrm_popup.Label1Click(Sender: TObject);
var
  ChatDistri: TChatDistri;
  jabberObj: TJabber;
begin
  if (Action = paPresence) then
  begin
    if Assigned(JabberObj) then
    begin
      ChatDistri := JabberObj.StartChat(jid, '', 'Nickname', True) as TChatDistri;
      ChatDistri.NewChat;
    end;
  end;
  Close;
end;

end.
